﻿
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Ebada.Platform.Model;
using DevExpress.XtraGrid.Columns;
using System.Reflection;
using Ebada.Client;
using DevExpress.XtraGrid.Views.Base;
using Ebada.Client.Platform;
using Ebada.UI.Base;
namespace Ebada.Modules.Vehicle
{

    public partial class UCVehicleDispatchEmp : DevExpress.XtraEditors.XtraUserControl {
        private GridViewOperation<VehicleDispatchEmp> gridViewOperation;

        public event SendDataEventHandler<VehicleDispatchEmp> FocusedRowChanged;
        public static bool FirstLoad = false;
        public string VehicleDispatchID = "";
        public int personnumber
        {
            get
            {
                return gridView1.RowCount;
            }

        }
        public UCVehicleDispatchEmp() 
        {
            InitializeComponent();
           
            gridViewOperation = new GridViewOperation<VehicleDispatchEmp>(gridControl1, gridView1, barManager1,new frmVehicleDispatchEmpEdit());
            gridViewOperation.CreatingObjectEvent +=gridViewOperation_CreatingObjectEvent;
            gridView1.FocusedRowChanged += new DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventHandler(gridViewOperation_FocusedRowChanged);
            gridViewOperation.BeforeAdd += new ObjectOperationEventHandler<VehicleDispatchEmp>(gridViewOperation_BeforeAdd);
            gridViewOperation.AfterAdd += new ObjectEventHandler<VehicleDispatchEmp>(gridViewOperation_AfterAdd);
            gridViewOperation.AfterDelete += new ObjectEventHandler<VehicleDispatchEmp>(gridViewOperation_AfterDelete);
           
            initColumns();
           
        }

        void gridViewOperation_AfterDelete(VehicleDispatchEmp obj)
        {
           
            frmVehicleDispatchEdit.parentfrom.PersonNum = personnumber;
        }

        void gridViewOperation_AfterAdd(VehicleDispatchEmp obj)
        {
            gridViewOperation.RefreshData(" where VehicleDispatchID='" + VehicleDispatchID + "'");
           
            frmVehicleDispatchEdit.parentfrom.PersonNum = personnumber;
        }

        void gridViewOperation_BeforeAdd(object render, ObjectOperationEventArgs<VehicleDispatchEmp> e)
        {
            e.Value.VehicleDispatchID = VehicleDispatchID;
        }

        void gridViewOperation_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e) 
        {
            if (FocusedRowChanged != null)
            {
                FocusedRowChanged(gridView1, gridView1.GetFocusedRow() as VehicleDispatchEmp);
                frmVehicleDispatchEdit.parentfrom.PersonNum = personnumber;
            }
        }
        


       
        /// <summary>
        /// 设置隐藏列
        /// </summary>
        /// 
       public  void initColumns() 
        {
            for (int i = 0; i < gridView1.Columns.Count; i++)
            {
                gridView1.Columns[i].Visible = false;
            }
            int m = 0;
            //gridView1.Columns["VehicleDispatchID"].Visible = true;
            gridView1.Columns["VehicleDispatchID"].VisibleIndex = m++;
            gridView1.Columns["VehicleDispatchID"].Caption = "派车单号";
            //gridView1.Columns["EmployeeNo"].Visible = true;
            gridView1.Columns["EmployeeNo"].VisibleIndex = m++;
            //gridView1.Columns["EmployeeName"].Visible = true;
            gridView1.Columns["EmployeeName"].VisibleIndex = m++;
            //gridView1.Columns["Remark"].Visible = true;
            gridView1.Columns["Remark"].VisibleIndex = m++;
            gridView1.Columns["Remark"].Caption = "备注";
           
        }
      
    
        /// <summary>
        /// 封装了数据操作的对象
        /// </summary>
        [Browsable(false)]
       public GridViewOperation<VehicleDispatchEmp> GridViewOperation
       {
            get { return gridViewOperation; }
            set { gridViewOperation = value; }
        }
        /// <summary>
        /// 新建对象设置Key值
        /// </summary>
        /// <param name="newobj"></param>
        void gridViewOperation_CreatingObjectEvent(VehicleDispatchEmp newobj)
        {
            //newobj.VehicleDispatchEmpID = Guid.NewGuid().ToString();
           
           
        }

        public void InitData( string sql)
        {
            gridViewOperation.RefreshData(sql);
        }
      
       

    }
}
